# encoding: utf-8

from fastapi import APIRouter
from fastui import AnyComponent, FastUI
from fastui import components
from fastui.events import GoToEvent

router = APIRouter()


# 日常模块的默认页面
@router.get(path='/', response_model=FastUI, response_model_exclude_none=True)
def serverapi_main_default() -> list[AnyComponent]:
    return main_modelpages(
        components.Heading(text='欢迎', level=2)
    )


@router.get(path='/{path:path}', status_code=404)
async def api_404():
    return {'message': 'Not Found'}


# 首页模板
def main_modelpages(*coms: AnyComponent) -> list[AnyComponent]:
    return [
        components.Navbar(
            title='首页',
            title_event=GoToEvent(url='/'),
            start_links=[
                components.Link(
                    components=[components.Text(text='日常')],
                    on_click=GoToEvent(url='/reminder/YYS'),
                    active='startswith:/reminder',
                ),
                components.Link(
                    components=[components.Text(text='待添加')],
                ),
            ],
        ),
        components.Page(
            components=[
                *coms,
            ],
        ),
        components.Footer(
            extra_text='Design by LinHW',
            links=[
                components.Link(
                    components=[components.Text(text='gitee address')], on_click=GoToEvent(url='https://gitee.com/LinHW2000/gamewebtools')
                ),
            ],
        ),
    ]